package com.jiayi.web.controller.cms;

import com.jiayi.api.JiayiProductTypeService;
import com.jiayi.common.annotation.Log;
import com.jiayi.common.core.domain.AjaxResult;
import com.jiayi.common.core.page.TableDataInfo;
import com.jiayi.common.developutil.ConvertUtils;
import com.jiayi.common.enums.BusinessType;
import com.jiayi.data.converter.JiayiProductTypeConverter;
import com.jiayi.data.entity.request.JiayiProductTypeRequest;
import com.jiayi.data.entity.request.JiayiProductTypeSearchPageRequest;
import com.jiayi.data.entity.request.JiayiProductTypeSearchRequest;
import com.jiayi.data.entity.schema.JiayiProductType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品展示类型Controller
 *
 * @author zzx
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/cms/jiayi_product_type")
public class JiayiProductTypeController {
    @Autowired
    private JiayiProductTypeService jiayiProductTypeService;

    @Autowired
    private JiayiProductTypeConverter jiayiProductTypeconverter;

    /**
     * 查询产品展示类型列表 分页
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product_type:list')")
    @PostMapping("/listPage")
    public TableDataInfo listPage(@RequestBody JiayiProductTypeSearchPageRequest request) {
        return jiayiProductTypeService.selectJiayiProductTypeList(request);
    }


    /**
     * 查询产品展示类型列表 不分页
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product_type:list')")
    @PostMapping("/list")
    public AjaxResult list(@RequestBody JiayiProductTypeSearchRequest request) {
        List<JiayiProductType> list = jiayiProductTypeService.selectJiayiProductTypeList(request);
        return AjaxResult.success(ConvertUtils.convert(list, jiayiProductTypeconverter::convertToJiayiProductTypeDTO));
    }

    /**
     * 导出产品展示类型列表
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product_type:export')")
    @Log(title = "产品展示类型" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@RequestBody JiayiProductTypeSearchRequest request, HttpServletResponse response) {
        jiayiProductTypeService.export(request, response);
    }

    /**
     * 获取产品展示类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product_type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(jiayiProductTypeService.selectJiayiProductTypeById(id));
    }

    /**
     * 新增产品展示类型
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product_type:add')")
    @Log(title = "产品展示类型" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JiayiProductTypeRequest request) {
        return AjaxResult.toAjax(jiayiProductTypeService.insertJiayiProductType(request));
    }

    /**
     * 修改产品展示类型
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product_type:edit')")
    @Log(title = "产品展示类型" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JiayiProductTypeRequest request) {
        return AjaxResult.toAjax(jiayiProductTypeService.updateJiayiProductType(request));
    }

    /**
     * 删除产品展示类型
     */
    @PreAuthorize("@ss.hasPermi('cms:jiayi_product_type:remove')")
    @Log(title = "产品展示类型" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return AjaxResult.toAjax(jiayiProductTypeService.deleteJiayiProductTypeByIds(ids));
    }
}
